<template>
	<view>
		<view class="input-group">
			<view class="flex-row input-view">
				<!-- <image class="input-left-img" src="../../static/img/user.png" mode="scaleToFill"></image> -->
				<view class="search-input">
					<input class="search-input" type="text" placeholder-class="input-placeholder" placeholder="请设置APP的服务器地址"
						v-model="serverAddress">
				</view>
				<!-- <image class="dropdown-img" src="../../static/img/dropdown.png" mode="scaleToFill"></image> -->
			</view>
		</view>
		<view class="submit-btn" @tap="testServer">
			<text>测试服务器地址</text>
		</view>
		<view class="submit-btn" @tap="changeServer">
			<text>修改服务器地址</text>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	var that;
	export default {
		data() {
			return {
				serverAddress: ''
			}
		},
		computed: {
			...mapState({
				userInfo: state => state.userInfo, // userInfo
				Token: state => state.Token, // Token
			})
		},
		onLoad() {
			that = this;
			let server = uni.getStorageSync('server');
			if(server) {
				that.serverAddress = server;
			}
		},
		methods: {
			testServer() {
				var that = this;
				debugger
				if(that.serverAddress === '') {
					that.$common.showNormalToast('请设置服务器地址！');
					return;
				}
				uni.showLoading({
					title:'加载中'
				})	
				var rq = {
					username: '18679186772',
					password: that.$common.MD5('123456')
				}
				
				
				let requestData = {
					token: '',
					loginMark: 'App',
					data: JSON.stringify(rq)					
				}		
				uni.request({
					url: 'http://'+that.serverAddress+'/learun/hospital/' + 'user/login',
					method:'POST',
					data:requestData,
					dataType: 'json',
				}).then((res) => {				
					uni.hideLoading()
					that.$common.showNormalToast('连接成功');
					
				}).catch((res) => {
			
					uni.hideLoading()
					that.$common.showNormalToast(res);		
				})
				
			},
			changeServer() {
				if(that.serverAddress === '') {
					uni.clearStorageSync('server')
					that.$common.showNormalToast('请设置服务器地址！');
					return;
				}
				uni.setStorageSync('server', that.serverAddress)
				that.$common.showNormalToast('修改成功');
				that.back()
			},
			back() {
				uni.redirectTo({
					url:'/pages/index/index'
				})
			}
		}
	}
</script>

<style>
@import url("server.css");
</style>
